﻿using Common;
using Microsoft.AspNetCore.Http;
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace AdminWeb.Models
{
    public static class BaseOperater
    {

        /// <summary>
        /// 获取登录用户信息
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public static Member getAdmin(HttpContext context)
        {
            string jsonUser = context.Session.GetString("adminuser");
            if (!string.IsNullOrWhiteSpace(jsonUser))
            {
                Member user = JSONHelper.DeserializeJsonToObject<Member>(jsonUser);
                return user;
            }
            return null;
        }

        /// <summary>
        /// 重新设置登录用户对象
        /// </summary>
        /// <param name="context"></param>
        /// <param name="model"></param>
        public static bool setAdmin(HttpContext context, Member model)
        {
            context.Session.SetString("adminuser",JSONHelper.SerializeObject(model));
            return true;
        }
    }
}
